package com.llsydn.ui.component.simple;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import com.llsydn.hello.R;

/**
 * @author lilinshen
 * @title 简单常用的component组件
 * @description 请填写相关描述
 * @date 2018/9/20 13:47
 */
public class SimpleComponentActivity extends Activity {
    private TextView txt_view_1;
    private EditText edt_text_1;
    private Button btn_submit_1;
    private ImageView iv_play_1;
    private CheckBox cb_lanqiu;
    private CheckBox cb_foot;
    private CheckBox cb_pinpon;
    private RadioGroup rg_item;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_simple_component_activity);

        //1.TextView
        txt_view_1 = findViewById(R.id.txt_view_1);
        txt_view_1.setText("llsydn的TextView");

        //2.EditText
        edt_text_1 = findViewById(R.id.edt_text_1);

        //3.Button
        btn_submit_1 = findViewById(R.id.btn_submit_1);
        btn_submit_1.setOnClickListener((v) -> {
            String number = edt_text_1.getText().toString();
            Toast.makeText(SimpleComponentActivity.this, number, Toast.LENGTH_SHORT).show();
        });

        //4.ImageView
        iv_play_1 = findViewById(R.id.iv_play_1);
        iv_play_1.setOnClickListener((v) -> {
            //设置背景图片
            iv_play_1.setBackgroundResource(android.R.drawable.alert_light_frame);
            //设置前景图片
            iv_play_1.setImageResource(android.R.drawable.ic_media_pause);
        });

        //5.Checkbox
        cb_lanqiu = findViewById(R.id.cb_lanqiu);
        cb_foot = findViewById(R.id.cb_foot);
        cb_pinpon = findViewById(R.id.cb_pinpon);
        cb_foot.setOnCheckedChangeListener((buttonView, isChecked) -> {
            if (isChecked) {
                Toast.makeText(SimpleComponentActivity.this, "足球被选中", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(SimpleComponentActivity.this, "足球未被选中", Toast.LENGTH_SHORT).show();
            }
        });

        //6.Radio
        rg_item = findViewById(R.id.rg_item);
        rg_item.setOnCheckedChangeListener((group, checkedId) -> {
            //找到选中的radioButton
            RadioButton radioButton = (RadioButton) findViewById(checkedId);
            //得到文本
            String sex = radioButton.getText().toString();
            //提示
            Toast.makeText(SimpleComponentActivity.this, sex, Toast.LENGTH_SHORT).show();
        });
    }


    /**
     * checkbox确定事件
     *
     * @param view
     */
    public void submit(View view) {
        StringBuffer stringBuffer = new StringBuffer();
        if (cb_lanqiu.isChecked()) {
            stringBuffer.append(" 篮球 ");
        }
        if (cb_foot.isChecked()) {
            stringBuffer.append(" 足球 ");
        }
        if (cb_pinpon.isChecked()) {
            stringBuffer.append(" 乒乓球 ");
        }
        Toast.makeText(SimpleComponentActivity.this, stringBuffer.toString(), Toast.LENGTH_SHORT).show();
    }

}
